package com.giantlizard.cloud.system.controller;

import com.giantlizard.cloud.base.generics.R;
import com.giantlizard.cloud.system.entity.SysRole;
import com.giantlizard.cloud.system.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统-角色 控制器
 */
@RestController
@RequestMapping("/role")
@Api(value = "系统-角色", tags = {"系统-角色"})
public class SysRoleController {

    private final SysRoleService sysRoleService;

    public SysRoleController(SysRoleService sysRoleService) {
        this.sysRoleService = sysRoleService;
    }

    @ApiOperation(value = "获取所有角色")
    @GetMapping("/list")
    public R<List<SysRole>> list() {
        return R.ok(sysRoleService.list());
    }

    @ApiOperation(value = "根据ID获取角色")
    @GetMapping("/{id}")
    public R<SysRole> getById(@ApiParam(name = "id", required = true, value = "角色ID") @PathVariable String id) {
        return R.ok(sysRoleService.getById(id));
    }

    @ApiOperation(value = "新增角色")
    @PostMapping
    public R<Boolean> add(@RequestBody SysRole sysRole) {
        return R.ok(sysRoleService.save(sysRole));
    }

    @ApiOperation(value = "更新角色")
    @PutMapping
    public R<Boolean> update(@RequestBody SysRole sysRole) {
        return R.ok(sysRoleService.updateById(sysRole));
    }

    @ApiOperation(value = "删除角色")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@ApiParam(name = "id", required = true, value = "角色ID") @PathVariable String id) {
        return R.ok(sysRoleService.removeById(id));
    }
} 